<?php

declare (strict_types=1);

namespace App\Application\Admin\Model;

use App\Application\Admin\Service\AccessService;
use Hyperf\Database\Model\Relations\HasMany;
use Hyperf\DbConnection\Model\Model;
use Hyperf\ModelCache\Cacheable;

/**
 * @property int                                            $city_id
 * @property int                                            $parent_city_id
 * @property string                                         $label
 * @property string                                         $merger_name
 * @property string                                         $value
 * @property-read \Hyperf\Database\Model\Collection|City[]  $children
 */
class City extends Model
{
    use Cacheable;

    protected string $primaryKey = 'city_id';
    /**
     * The table associated with the model.
     *
     * @var ?string
     */
    protected ?string $table = 'city';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected array $fillable = ['city_id', 'parent_city_id', 'label',  'value'];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected array $casts = [
        'city_id' => 'integer',
        'parent_city_id' => 'integer',
        'label' => 'string',
        'value' => 'string',
        'created_at' => 'datetime',
        'updated_at' => 'datetime'
    ];
    const IS_MENU_YES = 1;
    const IS_MENU_NO = 0;

    public function children(): HasMany
    {
        //关联的数据也需要排序
        return $this->hasMany(City::class, 'parent_city_id', 'city_id')
            ->orderBy('city_id');
    }



}